package com.example.smartcitydemo.viewModel.person

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.switchMap
import com.example.smartcitydemo.bean.ModifyPassword
import com.example.smartcitydemo.bean.ModifyPersonInfo
import com.example.smartcitydemo.bean.ReplyMessage
import com.example.smartcitydemo.ext.getLiveData
import com.example.smartcitydemo.repo.bus.BusRepo
import com.example.smartcitydemo.repo.person.PersonRepo

/**
 * @PACKAGE_NAME: com.example.smartcitydemo.viewModel.person
 * @NAME: Caleb.F
 * @DATE: 2021/11/11 8:45
 * @Email: 1919796283@qq.com
 */
class PersonViewModel : ViewModel() {
    private val mutablePersonInfo = MutableLiveData<String>()
    private val mutableModifyPersonInfo = MutableLiveData<ModifyPersonInfo>()
    private val mutableBusOrder = MutableLiveData<Int>()
    private val mutablePassword = MutableLiveData<ModifyPassword>()

    private val mutableReplyMessage = MutableLiveData<ReplyMessage>()

    private val mutableReplyList = MutableLiveData<String>()


    val personInfo = mutablePersonInfo.switchMap {
        getLiveData { PersonRepo.getPersonInfo() }
    }

    val modifyResult = mutableModifyPersonInfo.switchMap {
        Log.d("dede", ":$it ")
        getLiveData { PersonRepo.modifyPersonInfo(it) }
    }
    val busOrderList = mutableBusOrder.switchMap {
        getLiveData { BusRepo.getBusOrder(it) }
    }

    val modifyPassWordResult = mutablePassword.switchMap {
        getLiveData { PersonRepo.modifyPassword(it) }
    }

    val replyResult = mutableReplyMessage.switchMap {
        getLiveData { PersonRepo.replyMessage(it) }
    }

    val replyList = mutableReplyList.switchMap {
        getLiveData { PersonRepo.getReplyList() }
    }

    fun getPersonInfo() {
        mutablePersonInfo.value = mutablePersonInfo.value
    }

    fun modifyPersonInfo(modifyPersonInfo: ModifyPersonInfo) {
        Log.d("dede", "modifyPersonInfo: $modifyPersonInfo")
        mutableModifyPersonInfo.value = modifyPersonInfo
    }

    fun getBusOrder(statusId: Int) {
        mutableBusOrder.value = statusId
    }

    fun modifyPassWord(modifyPassword: ModifyPassword) {
        mutablePassword.value = modifyPassword
    }

    fun submitReplyMessage(replyMessage: ReplyMessage) {
        mutableReplyMessage.value = replyMessage
    }

    fun getReplyList() {
        mutableReplyList.value = mutableReplyList.value
    }
}